package com.ttctracker.util;

import java.util.Arrays;
import java.util.HashMap;

import com.ttctracker.classes.Direction;
import com.ttctracker.classes.Route;
import com.ttctracker.classes.StopItem;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyApp extends Application {
	private HashMap<String, String> routeTags;
	private Route selected_route;
	private Direction selected_direction;
	private StopItem selected_stop;
	private ArrayAdapter<String> routeAdapter;
	private String[] route_tags_keys, route_tags_titles;
	public static final boolean DEBUG=false;
	private static Configuration configuration;
	public static final String SKYHOOK_USERNAME="wcai";
	public static final String SKYHOOK_REALM="wcaiapp";
	
	public HashMap<String, String> getRouteTags() {
		return routeTags;
	}

	public void setRouteTags(HashMap<String, String> routeTags) {
		this.routeTags = routeTags;
	}

	public Route getSelected_route() {
		return selected_route;
	}

	public void setSelected_route(Route selected_route) {
		this.selected_route = selected_route;
	}

	public Direction getSelected_direction() {
		return selected_direction;
	}

	public void setSelected_direction(Direction selected_direction) {
		this.selected_direction = selected_direction;
	}

	public StopItem getSelected_stop() {
		return selected_stop;
	}

	public void setSelected_stop(StopItem selected_stop) {
		this.selected_stop = selected_stop;
	}

	public ArrayAdapter<String> getRouteAdapter() {
		return routeAdapter;
	}

	public String[] getRoute_tags_keys() {
		return route_tags_keys;
	}

	public String[] getRoute_tags_titles() {
		return route_tags_titles;
	}

	public void setupRouteArrayAdapter() {
		if (routeTags != null && routeTags.size() > 0) {
			route_tags_keys = routeTags.keySet().toArray(
					new String[routeTags.size()]);
			route_tags_titles = routeTags.values().toArray(
					new String[routeTags.size()]);

			Arrays.sort(route_tags_keys);
			Arrays.sort(route_tags_titles);

			routeAdapter = new ArrayAdapter<String>(this,
					android.R.layout.simple_dropdown_item_1line,
					route_tags_titles);/*{
				@Override
				public View getView(int position, View convertView,
						ViewGroup parent) {
					View v = convertView;
					if (v == null) {
						LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
								Context.LAYOUT_INFLATER_SERVICE);
						v = vi.inflate(R.layout.normal_dropdown_item, null);
					}
					
					
						TextView txt=(TextView)v.findViewById(R.id.textView1);
						txt.setText(getItem(position));
					
					return v;

				}
			}*/;
		}

	}
	
	public static String getDBName(){
		return SqlOpenHelper.getDatabaseName();
	}
	
	public static void hideKeyBoard(Activity activity, TextView textView) {
		textView.requestFocus();
		 InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
	       /* if (keyBoardShown()) {
				imm.toggleSoftInput(0, 0);
			}*/
		 imm.hideSoftInputFromWindow(textView.getWindowToken(), 0);
	    
	}
	
	public static boolean keyBoardShown() {
		if (configuration==null) {
			configuration=Resources.getSystem().getConfiguration();
		}
		return configuration.keyboardHidden==Configuration.KEYBOARDHIDDEN_NO;
	}

}
